<?php

namespace App\Admin\Controllers;

use App\Models\City;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;

use Dcat\Admin\Tree;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;


class CityController extends AdminController
{
    protected $title='城市管理';
    public function index(Content $content)
    {
        return $content->header('树状模型')
            ->body(function (Row $row) {
                $tree = new Tree(new City());

                $row->column(12, $tree);
            });
    }
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new City(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new City(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('lat');
            $show->field('lng');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new City(), function (Form $form) {
            $form->display('id');
            $form->text('name','名称')->required();
            $form->text('pinyin','拼音')->required();
            $form->text('first','首字母缩写')->required();
            $form->map('lat','lng','经纬度')->required();
        });
    }
}

